//
//  RCRecommendFoodDetailDataModel.m
//  RocketProject
//
//  Created by Wu Chengwei on 13-9-24.
//  Copyright (c) 2013年 Rocket. All rights reserved.
//

#import "RCRecommendFoodDetailDataModel.h"
#import "FrameworkRelativeDefines.h"
#import "RCMerchantDetailDataModel.h"


@implementation RCRecommendFoodDetailDataModel

@synthesize shopID = _shopID;
@synthesize shopName = _shopName;
@synthesize foodName = _foodName;
@synthesize foodDesc = _foodDesc;
@synthesize foodPrice = _foodPrice;
@synthesize foodDistance = _foodDistance;
@synthesize foodDetailItems = _foodDetailItems;
@synthesize foodImageUrl = _foodImageUrl;
@synthesize foodLat = _foodLat;
@synthesize foodLon = _foodLon;
@synthesize foodScore = _foodScore;


- (void) dealloc
{
    self.shopID = nil;
    self.shopName = nil;
    self.foodName = nil;
    self.foodPrice = nil;
    self.foodDistance = nil;
    self.foodDetailItems = nil;
    self.foodDesc = nil;
    self.foodImageUrl = nil;
    self.foodLon = nil;
    self.foodLat = nil;
    [super dealloc];
}


// 将JSON数据解析为数据模型
-(id) parseDataFromJSON:(NSDictionary*)data
{
    // 输入参数判断
    if ( nil == data )
        return nil;
    
    RCRecommendFoodDetailDataModel *retObject = nil;
    retObject = [[RCRecommendFoodDetailDataModel alloc] init];
    if ( nil == retObject )
        return retObject;
    
    
    NSDictionary *dataDic = [data dictionaryValueForKey:@"data" defaultValue:nil];
    
    retObject.shopID = [dataDic stringValueForKey:@"shopid" defaultValue:nil operation:NSStringOperationTypeNone];
    retObject.shopName = [dataDic stringValueForKey:@"shopname" defaultValue:nil operation:NSStringOperationTypeNone];
    retObject.foodName = [dataDic stringValueForKey:@"foodname" defaultValue:nil operation:NSStringOperationTypeNone];
    retObject.foodPrice = [dataDic stringValueForKey:@"price" defaultValue:nil operation:NSStringOperationTypeNone];
    retObject.foodDesc = [dataDic stringValueForKey:@"desc" defaultValue:nil operation:NSStringOperationTypeNone];
    
    retObject.foodDistance = [dataDic stringValueForKey:@"distance" defaultValue:nil operation:NSStringOperationTypeNone];
    retObject.foodImageUrl = [dataDic stringValueForKey:@"picurl" defaultValue:nil operation:NSStringOperationTypeTrim];
    retObject.foodLon = [dataDic stringValueForKey:@"lon" defaultValue:nil operation:NSStringOperationTypeTrim];
    retObject.foodLat = [dataDic stringValueForKey:@"lat" defaultValue:nil operation:NSStringOperationTypeTrim];
    retObject.foodScore = [dataDic intValueForKey:@"score" defaultValue:0];

    int favourite = [dataDic intValueForKey:@"favorite" defaultValue:0];
    if (favourite == 1) {
        retObject.favourited = YES;
    }else{
        retObject.favourited = NO;
    }
    
    NSArray *t = [dataDic arrayValueForKey:@"list" defaultValue:nil];
    NSMutableArray *itemsArray = [[NSMutableArray alloc] init];
    for (NSDictionary *dic in t) {
        RCMerchantDetailItem *item = [[RCMerchantDetailItem alloc] initWithDic:dic];
        [itemsArray addObject:item];
        [item release];
    }
    
    //添加交通等
    
    RCMerchantDetailItem *traffic = [[RCMerchantDetailItem alloc]init];
    traffic.type = kMerchantDetailType_Traffic;
    traffic.content = @"交通、营业时间及其他";
    [itemsArray addObject:traffic];
    [traffic release];
    
    NSInteger otherShop = [dataDic intValueForKey:@"othershop" defaultValue:0];
    if (otherShop == 1) {
        RCMerchantDetailItem *otherShop = [[RCMerchantDetailItem alloc]init];
        otherShop.type = kMerchantDetailType_Othershop;
        otherShop.content = @"其他分店";
        [itemsArray addObject:otherShop];
        [otherShop release];
    }
    retObject.foodDetailItems = itemsArray;
    [itemsArray release];
    
    return [retObject autorelease];
    
}

@end
